package com.lin.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.DbUtils;

import com.lin.dao.CategoryDaoImpl;
import com.lin.dao.ICategoryDao;
import com.lin.utils.JdbcUtils;
import com.lin.vo.Category;

public class CategoryServiceImpl implements ICategoryService {
	private ICategoryDao categoryDao=new CategoryDaoImpl();
	@Override
	public List<Category> findAllCategory() {
		return categoryDao.findAllCategory();
	}
	@Override
	public void addCategory(Category category) {
		categoryDao.addCategory(category);
		
	}
	@Override
	public Category findByCategoryCid(String cid) {
		return categoryDao.findByCategoryCid(cid);
	}
	@Override
	public void updateCategory(Category category) {
		categoryDao.updateCategory(category);
		
	}
	@Override
	public void deleteByCategoryCid(Category category) {
		Connection connection =null;
		try {
			connection = JdbcUtils.getConnection();
			// 开启手动提交事物
			connection.setAutoCommit(false);
			categoryDao.deleteByCategoryCid(connection,category);
			// 提交事务
			DbUtils.commitAndCloseQuietly(connection);
		} catch (Exception e) {
			// 回滚事务
			DbUtils.commitAndCloseQuietly(connection);
			e.printStackTrace();
		}
		
	}

}
